package com.abstralabs.time;

import java.util.ArrayList;
import java.util.Calendar;


public class HistoryDina{ //implements Parcelable{
	
	String activity;
	int loop=0;         // 0 - inactive, 1 - active
	int sumDay=0;       //in second
	int sumDayLast=0;
	ArrayList <Long> year=new ArrayList<Long>();
	ArrayList <Long> month=new ArrayList<Long>();
	ArrayList <Long> day=new ArrayList<Long>();
	//ArrayList <Long> hour=new ArrayList<Long>();
	//ArrayList <Long> minute=new ArrayList<Long>();
	ArrayList <Long> second=new ArrayList<Long>();
	
//	public History (Parcel in){
//		this.loop=in.readInt();
//		this.sumDay=in.readInt();
//		this.sumDayLast=in.readInt();
//		int count=in.readInt();
//		for (int i=0; i<count;i++){
//			year.add(in.readLong());
//			month.add(in.readLong());
//			day.add(in.readLong());
//			//hour.add(in.readLong());
//			//minute.add(in.readLong());
//			second.add(in.readLong());
//		}
//	}
	
	public HistoryDina(String activity) {
		this.activity=activity;
	}
	
	public void saveHistory (Calendar calnow){
			
		year.add((long)calnow.get(Calendar.YEAR));
		month.add((long)calnow.get(Calendar.MONTH));
		day.add((long)calnow.get(Calendar.DAY_OF_MONTH));
		//hour.add((long)calnow.get(Calendar.HOUR));
		//minute.add((long)calnow.get(Calendar.MINUTE));
		second.add((long)calnow.get(Calendar.SECOND)+(long)calnow.get(Calendar.MINUTE)*60+(long)calnow.get(Calendar.HOUR)*3600);
		if (loop==1){
			loop=0;
			sumDay=(int) (sumDayLast+second.get(month.size()-1)-second.get(month.size()-2));
			sumDayLast=sumDay;
		}
		else loop=1;
		
	}
	
//	public int describeContents() {
//		// TODO Auto-generated method stub
//		return 0;
//	}
	
//	public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
//		 
//	    public History createFromParcel(Parcel in) {
//	      return new History(in);
//	    }
//	 
//	    public History[] newArray(int size) {
//	      return new History[size];
//	    }
//	  };
	  
//	public void writeToParcel(Parcel dest, int flags) {
//		// TODO Auto-generated method stub
//		dest.writeInt(loop);
//		dest.writeInt(sumDay);
//		dest.writeInt(sumDayLast);
//		dest.writeInt(month.size());
//		for (int i=0; i<month.size();i++){
//			dest.writeLong(year.get(i));
//			dest.writeLong(month.get(i));
//			dest.writeLong(day.get(i));
//			//dest.writeLong(hour.get(i));
//			//dest.writeLong(minute.get(i));
//			dest.writeLong(second.get(i));
//		}
//	}
	
	
	public void newDay(){
		sumDay=0;
		Calendar calnow=Calendar.getInstance();
		if (loop==1)
			sumDayLast=(int) (second.get(month.size()-1)-(int)calnow.get(Calendar.SECOND)-(int)calnow.get(Calendar.MINUTE)*60-(int)calnow.get(Calendar.HOUR)*3600);
		else
		sumDayLast=0;
	}
	
	public void updateSumDay(){
		if (loop==1){
			Calendar calnow=Calendar.getInstance();
			sumDay=(int) (sumDayLast-second.get(month.size()-1)+(int)calnow.get(Calendar.SECOND)+(int)calnow.get(Calendar.MINUTE)*60+(int)calnow.get(Calendar.HOUR)*3600);
		}
	}
}